<template>
	<view>
		<uni-section class="mb-10" title="仓库:">
			<template v-slot:right>
				<view style="width: 550rpx;">
					<uni-data-select v-model="warehouseNo" :localdata="range" @change="selectFun"></uni-data-select>
				</view>
			</template>
		</uni-section>
		<uni-section class="mb-10" title="货号过滤:">
			<template v-slot:right>
			<!-- 	<liu-bubble-menu elementId="huohao" :dataList="selectData" @change="change2" bgColor="#ec622a"
					:dWidth="300" :dHeight="250"> -->
					<view style="width: 550rpx;" id="huohao">
						<!-- <uni-easyinput type="text" confirmType="search" @change="searchFun"></uni-easyinput> -->
						<!-- <uni-data-select v-model="goodsNum"  :localdata="selectList" @change="searchFun"></uni-data-select> -->
						<uni-combox   :candidates="selectList" placeholder="请输入货号" @input="searchFun"></uni-combox>
					</view>
				<!-- </liu-bubble-menu> -->

			</template>
		</uni-section>
		<uni-section class="mb-10" title="次品筛选:">
			<template v-slot:right>
				<view style="width: 550rpx;">
					  <uni-data-select      :localdata="cipin"   @change="ciPinFun"   ></uni-data-select>
				</view>
			</template>
		</uni-section>
		
		<zb-table :show-header="true" :columns="column" :stripe="true" :fit="false"
			@toggleRowSelection="toggleRowSelection" @toggleAllSelection="toggleAllSelection" :border="true"
			:data="data"></zb-table>
		<uni-pagination title="标题文字" :total="total" @change="pageFun"></uni-pagination>
		<view style="text-align: center; ">
			<button plain="true" size="default" @click="successFun">完成</button>
		</view>
	</view>
</template>

<script>
	import {
		stockList,
		orderMainPage,
		orderMainGetSelectList,stockByUserList
	} from '../../config/api.js';
	export default {
		data() {
			return {
				column: [{
						type: 'selection',
						fixed: true,
						width: 50
					},
					{
						name: 'purchaseNo',
						label: '采购单号',
						fixed: false,
						width: 180
					},
					{
						name: 'warehouseName',
						label: '仓库名称',
						fixed: false,
						width: 100
					},
					{
						name: 'providerName',
						label: '供应商名称'
					},
					{
						name: 'goodsCount',
						label: '采购数量'
					},
					{
						name: 'goodsArriveCount',
						label: '到货数量'
					},
					{
						name: 'goodsStockinCount',
						label: '入库量'
					},
					// { name: 'purchaseNo', label: '采购单号',fixed:false,width:80,emptyString:'--' },
					// { name: 'age', label: '年纪',sorter:false,align:'right', },
					// { name: 'sex', label: '性别',filters:{0:'男',1:'女'}},
					// { name: 'img', label: '图片',type:"img" },
					// { name: 'address', label: '地址' },
					// { name: 'date', label: '日期',sorter:true },
					// { name: 'province', label: '省份' },
					// { name: 'city', label: '城市' },
					// { name: 'zip', label: '邮编' },
					// { name: 'operation', type:'operation',label: '操作',renders:[
					//     {
					//       name:'编辑',
					//       func:'edit' // func 代表子元素点击的事件 父元素接收的事件 父元素 @edit
					//     },
					//     {
					//       name:'删除',
					//       type:'warn',
					//       func:"dele"
					//     },
					//   ]},
				],
				data: [],
				cipin: [
        { value: null, text: "全部" },
        { value: 1, text: "次品" },
        { value: 2, text: "非次品" },
      ],
				cipinSelect:"",
				dataList: ['选项1', '选项2', '选项3', '选项4'],
				searchVal: '',
				range: [],
				warehouseNo: '',
				tableData: [],
				// 每页数据量
				pageSize: 10,
				// 当前页
				pageCurrent: 1,
				// 数据总量
				total: 0,
				stockName: 0,
				warehouseNo: "",
				goodsNum: "",
				timer: null,
				selectData: [],
				selectList: [],
				relacationShopNum: "",
				loading: false
			}
		},
		onShow() {
			let cacheData = uni.getStorageSync("userInfoByPDA");
			this.stockName = cacheData.stockName
			this.warehouseNo = cacheData.warehouseNo
			this.relacationShopNum = cacheData.relacationShopNum
			this.orderMainGetSelectListFun();
			this.stockListFun();
			this.orderMainPageFun(this.pageCurrent);
			console.log(this.stockName)
		},
		methods: {
			changeCiPin(e) {
				 console.log(e)
			},
			pageFun(e) {
				this.pageCurrent = e.current
				this.orderMainPageFun();
			},
			toggleAllSelection(e) {
				console.log(e)
			},
			toggleRowSelection(e, data) {
				this.selectData = data;
				if (this.selectData.length > 1) {
					uni.showToast({
						title: "请只选择一项",
						icon: "none"
					})
				}
			},
			orderMainPageFun() {
				let that = this;
				// get请求
				orderMainPage({
					custom: {
						auth: true
					},
					params: {
						warehouseNo: this.warehouseNo,
						goodsNum: this.goodsNum,
						cipin: this.cipinSelect,
						pageNum: this.pageCurrent,
					},
				}).then((e) => {
					if (e.code == 200) {
						that.data = e.data
						that.total = e.count
					}
				}).catch((e) => {
					console.log(e)
				})
			},
			orderMainGetSelectListFun() {
				let that = this;
				// get请求
				orderMainGetSelectList({
					custom: {
						auth: true
					},
					params: {
						warehouseNo: this.warehouseNo
					},
				}).then((e) => {
					if (e.code == 200) {
						for (var i = 0; i < e.data.length; i++) {
							console.log(e.data[i].goodsNo)
							that.selectList.push(e.data[i].goodsNo)
						}
					}
				}).catch((e) => {
					console.log(e)
				})
			},
			// 多选处理
			selectedItems() {
				return this.selectedIndexs.map(i => this.tableData[i])
			},
			// 多选
			selectionChange(e) {
				console.log(e.detail.index)
				this.selectedIndexs = e.detail.index
			},
			//批量删除
			delTable() {
				console.log(this.selectedItems())
			},
			// 分页触发
			change(e) {
				this.$refs.table.clearSelection()
				this.selectedIndexs.length = 0
				this.getData(e.current)
			},


			successFun() {
				if (this.selectData.length > 1) {
					uni.showToast({
						title: "请只选择一项",
						icon: "none"
					})
					return
				}
				if (this.selectData.length < 1) {
					uni.showToast({
						title: "请至少选择一项",
						icon: "none"
					})
					return
				}
				uni.navigateTo({
					url: "/pages/gongchang/gongchang?goodsNum="+this.goodsNum+"&json=" + JSON.stringify(this.selectData[0]),
				})
			},
			ciPinFun(e) {
				console.log(e)
				this.cipinSelect = e;
				this.pageCurrent = 1;
				this.orderMainPageFun();
			},
			selectFun(e) {
				console.log(e)
				this.warehouseNo = e;
				this.pageCurrent = 1;
				this.orderMainPageFun();
			},
			searchFun(e) {	
				console.log(e)
				let that=this;
				that.goodsNum=e
				clearInterval(this.timer)
				this.timer=setTimeout(function(){
					that.pageCurrent = 1;
					
					that.orderMainPageFun();
				},1000)
			
			},
			stockListFun() {
				let that = this;
				that.range.push({
					value: "011",
					text: "温州科一仓"
				})
		 
				that.range.push({
					value: "025",
					text: "天猫预入库"
				})
		 
				// get请求
				// stockByUserList({
				// 	custom: {auth:true},
				// 	params: {}
				// }).then((e) => {
				// 	console.log(e)
				// 	if (e.code == 200) {
				// 		for (var i = 0; i < e.data.length; i++) {
				// 			that.range.push({
				// 				value: e.data[i].stockNo,
				// 				text: e.data[i].stockName
				// 			})
				// 		}
				// 	}
				// }).catch((e) => {
				// 	console.log(e)
				// })
			},
		}
	}
</script>

<style>

</style>